﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
    /// <summary>
    /// Extension methods for Enums
    /// </summary>
    public static class EnumExt
    {
        /// <summary>
        /// Determines whether enum [contains] [the specified value].
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool Contains<T>(this T source, T value) where T : struct, IComparable, IFormattable, IConvertible
        {
            try
            {
                if (typeof(T).IsEnum)
                {
                    Enum en1 = (Enum)((object)source);
                    Enum en2 = (Enum)((object)value);

                    if (en1.HasFlag(en2))
                        return true;
                }
            }
            catch { }
            return false;
        }
    }
}
